assert {[have_include power_on/qemu] || [have_spec linux]}

create_boot_directory

build {
	core init timer lib/ld lib/libc lib/posix lib/vfs_import
	server/vfs_block
	test/libc_block
}

install_config {
<config verbose="yes">
	<parent-provides>
		<service name="ROM"/>
		<service name="IRQ"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
	</parent-provides>
	<default-route>
		<any-service> <parent/> <any-child/> </any-service>
	</default-route>
	<default caps="200" ram="1M"/>
	<start name="timer">
		<provides> <service name="Timer"/> </provides>
	</start>
	<start name="test-libc_block" ram="2M">
		<config>
			<libc stdout="/dev/log"/>
			<vfs>
				<dir name="dev">
					<log/>
					<block name="blkdev"/>
				</dir>
			</vfs>
		</config>
	</start>
	<start name="vfs_block" ram="68M">
		<provides><service name="Block"/></provides>
		<config>
			<vfs>
				<ram/>
				<import>
					<zero name="test.hda" size="64M"/>
				</import>
			</vfs>
			<default-policy file="/test.hda" block_size="512"
			                writeable="yes"/>
		</config>
	</start>
</config>
}

#
# Boot modules
#

set disk_image "bin/test.hda"
set cmd "dd if=/dev/zero of=$disk_image bs=1024 count=65536"
puts "creating disk image: $cmd"
catch { exec sh -c $cmd }

build_boot_image [list {*}[build_artifacts] test.hda]

append qemu_args " -nographic "

run_genode_until {.*child "test-libc_block" exited with exit value 0.*} 60

exec rm -f $disk_image

puts "\nTest succeeded\n"

# vi: set ft=tcl :
